﻿namespace Digitalmes.Application.Sys.Menus.Commands;

/// <summary>
/// 更新菜单命令。
/// </summary>
public record UpdateMenuCommand(SysMenuDto Menu) : IRequest<IResult<bool>>;

internal sealed class UpdateMenuCommandHandler(IRepository<SysMenu> repo) : IRequestHandler<UpdateMenuCommand, IResult<bool>>
{
    public async Task<IResult<bool>> Handle(UpdateMenuCommand request, CancellationToken cancellationToken)
    {
        var menu = request.Menu.Adapt<SysMenu>();
        var ok = await repo.UpdateAsync(menu, m => new 
        {
            m.ParentId,
            m.MenuType,
            m.Title,
            m.Name,
            m.Path,
            m.Component,
            m.Rank,
            m.Redirect,
            m.Icon,
            m.ExtraIcon,
            m.EnterTransition,
            m.LeaveTransition,
            m.ActivePath,
            m.Auths,
            m.FrameSrc,
            m.FrameLoading,
            m.KeepAlive,
            m.HiddenTag,
            m.FixedTag,
            m.ShowLink,
            m.ShowParent,
            m.LastModifiedBy,
            m.LastModifiedTime,
        }, cancellationToken);
        return Result.From(ok);
    }
}
